using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using Condimar.Entities;

namespace Condimar.Repository.Mapping
{
    public class ComprobanteMap : EntityTypeConfiguration<Comprobante>
    {
        public ComprobanteMap()
        {
            // Primary Key
            this.HasKey(t => t.Id);

            // Properties
            this.Property(t => t.Id)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(t => t.NroSerie)
                .IsRequired()
                .HasMaxLength(100);

            this.Property(t => t.Nro_Comprobante)
                .HasMaxLength(100);

            this.Property(t => t.TipoComprobante)
                .HasMaxLength(100);

            // Table & Column Mappings
            this.ToTable("Comprobante");
            this.Property(t => t.Id).HasColumnName("Id");
            this.Property(t => t.NroSerie).HasColumnName("NroSerie");
            this.Property(t => t.Nro_Comprobante).HasColumnName("Nro.Comprobante");
            this.Property(t => t.TipoComprobante).HasColumnName("TipoComprobante");
            this.Property(t => t.VentaId).HasColumnName("VentaId");
            this.Property(t => t.ProductoId).HasColumnName("ProductoId");

            // Relationships
            this.HasOptional(t => t.Producto)
                .WithMany(t => t.Comprobantes)
                .HasForeignKey(d => d.ProductoId);
            this.HasOptional(t => t.Venta)
                .WithMany(t => t.Comprobantes)
                .HasForeignKey(d => d.VentaId);

        }
    }
}
